/**
 * 插件初始化
 * @author harae
 */
$(function () {
    /* nicescroll */
    $('.nicescroll').niceScroll({
        cursorcolor: "#8e909a",cursorborder:"0px solid #fff",cursoropacitymax:"0.5",cursorborderradius:"0px"
    })

    /* counterup */
    $('.counter').counterUp({
        delay: 100,
        time: 1200
    });
})


// sideNav
!(function ($) {
    /* menu */
    function Nav(){
        this.$sideBar = $('aside.left-panel')
    }

    Nav.prototype = {
        Constructor: Nav,
        init: function () {
            this._toggleNav() // 左侧Nav开关 事件注册
            this._toggleItem() // 菜单点击 事件注册
        },
        _toggleNav: function () {
            let _this = this
            $(document).on('click', '.navbar-toggle', function () {
                $('aside.left-panel nav.navigation > ul > li.active > ul').slideToggle(300)
                _this.$sideBar.toggleClass("collapsed")
            })
        },
        _toggleItem: function () {
            var _this = this
            $(document).on('click', 'aside.left-panel nav.navigation > ul > li:has(ul) > a', function () {
                console.log(222)
                return 0 === _this.$sideBar.has('collapsed') || $(window).width() > 768 ?
                    (
                        $('aside.left-panel nav.navigation > ul > li > ul').slideUp(300),
                        $('aside.left-panel nav.navigation > ul > li').removeClass('active'),
                        $(this).next().is(":visible") || $(this).next().slideToggle(300,function() {
                            // 初始化滚动条
                            $("aside.left-panel:not(.collapsed)").getNiceScroll().resize()
                            $(this).closest("li").addClass("active")
                        })
                    ) : void (0)
            })
        }
    }

    $(function () {
        var sidenav = new Nav()
        sidenav.init()
    })

})(window.jQuery)